-- migrations-create.sql

begin;
------------------------------------------------------------

create table migrations (
  id          serial primary key,
  inserted    timestamptz(0) default current_timestamp,
  description text
);

create or replace function migrations_insert(varchar) returns text as $$
  insert into migrations (description) values ($1);
  select id::varchar||': '||description||' ('||inserted::varchar||')' from migrations where description=$1;
$$ language 'sql';

create or replace function migrations_delete(int) returns text as $$
  delete from migrations where id=$1;
  select '#'||$1::varchar -- dropped';
$$ language 'sql';

create or replace function migrations_delete(varchar) returns text as $$
  delete from migrations where description=$1;
  select '"'||$1||'" -- dropped';
$$ language 'sql';

select migrations_insert('migrations create');

---------------------------------------------------------------------------
commit;

